<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../include/base.jsp"%>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>凯盛项目管理系统</title>
	<meta charset="UTF-8">
	<title>欢迎使用CRM管理系统</title>
    <link rel="stylesheet" href="${basePath }/css/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="${basePath }/css/style.css" type="text/css" />
    <script type="text/javascript" src="${basePath }/js/jquery.min.js"></script>
    <script type="text/javascript" src="${basePath }/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="navbar">
        <div class="navbar-inner">
            <div class="container">
                <a href="${basePath }/message" class="brand">凯盛CRM管理系统</a>
                <div class="nav-collapse">
                    <ul class="nav">
                        <li><a href="#">最新动态</a></li>
                        <li><a href="${basePath }/contacts/list">联系人</a></li>
                        <li><a href="${basePath }/task/list">日程安排</a></li>
                        <li><a href="${basePath }/deal/list">业务机会</a></li>
                    </ul>
                    <ul class="nav pull-right">
                        <li><a href="#">${user.username }</a></li>
                        <li class="divider-vertical"></li>
                        <li  class="active"><a href="#">账号设置</a></li>
                        <li><a href="${basePath }/user/loginout">退出</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <div id="content" class="container">
       	<div class="span3" style="float:left;">
			<div class="wall">
				<ul class="nav nav-list">
					<li class="nav-header">个人资料</li>
					<li class="divider"></li>
					<li class="active">
						<a href="user">
							<i class="icon-white icon-user"></i>个人资料
						</a>
					</li>
					<li>
						<a href="${basePath }/user/pwd">
							<i class="icon-qrcode"></i>修改密码
						</a>
					</li>
				</ul>
			</div>
		</div>
		<div class="span9" style="float:right;">
               <form action="${basePath }/user/info-edit" method="post" class="form-horizontal" id="myform">
               	   <input type="hidden" name="user.id" value="${user.id }">
               	   <input type="hidden" name="user.group.id" value="${user.group.id }">
                   <fieldset>           
                       <legend>修改个人资料</legend>
	                   <c:choose>
							<c:when test="${param.code == '1' }">
								<div class="alert alert-error">
									<button class="close" data-dismiss="alert">×</button>
									<strong>修改成功</strong>
								</div>
							</c:when>
							<c:when test="${param.code == '2' }">
								<div class="alert alert-error">
									<button class="close" data-dismiss="alert">×</button>
									<strong>密码错误，修改失败</strong>
								</div>
							</c:when>
						</c:choose>
						<div class="control-group">
	                           <label class="control-label">账户状态</label>
	                           <div class="controls">
	                               <input type="text" class="input-xlarge" name="user.enable" disabled="disabled" value="${user.enable }">
                           </div>
                      	</div>
						<div class="control-group">
	                        <label class="control-label" >分组</label>
	                        <div class="controls">
	                            <input type="text" class="input-xlarge"  name="user.group.groupName" disabled="disabled" value="${user.group.groupName }">
	                        </div>
	                    </div>
						<div class="control-group" id="nameDiv">
                           <label class="control-label">用户名</label>
                           <div class="controls">
                               <input type="text" id="name" class="input-xlarge" name="user.username" value="${user.username }">
                           </div>
                       </div>
						<div class="control-group" id ="emailDiv">
                           <label class="control-label" for="email" >Email</label>
                           <div class="controls">
                               <input type="text" class="input-xlarge" id="email" name="user.email" value="${user.email }">
                          		 <p class="help-block" id="pmail" ></p>
                           </div>
                       </div>
                       <div class="control-group">
                           <label class="control-label" for="company">输入确认密码</label>
                           <div class="controls">
                               <input type="password" class="input-xlarge" id="password" name="user.password">
                           </div>
                       </div>
                       <div class="form-actions">
                           <button class="btn btn-primary" type="button" id ="btn">修改</button>
                           <a href="main" class="btn">返回</a>
                       </div>
                   </fieldset>
               </form>
           </div>
    </div>
    <script type="text/javascript">
    	$(document).ready(function() {
    		var oldName = $("#name").val();
    		var oldEmail = $("#email").val();
    		
    		$("#email").focus(function() {
    			$("#emailDiv").removeClass("error");
    			$("#pmail").html("");
    		});
    		
	    	$("#email").blur(function() {
	    		var email = $(this).val();
	    		if(email.trim() == "") {
	    			$("#nameDiv").addClass("error");
	    			$("#pname").html("Email不能为空");
	    		} else if(email != oldEmail) {
	    			$.get("${basePath }/user/checkEmail",{"email":email},function(result){
	    				if(result == 0){
		                		$("#pmail").text("Email可用");
		                	} else {
		                		$("#pmail").text("Email已被占用！");
		                    	$("#emailDiv").addClass("error");
		                	} 
	    			});
	    		} 
	    	});
	    	$("#btn").click(function() {
	    		var name = $("#name").val();
    			var email = $("#email").val();
    			var password = $("#password").val();
    			if ((name != oldName || email != oldEmail) && name.trim() != "" && email.trim() != "" && password != "") {
    				$("#myform").submit();
    			}
	    	});
    	});
    </script>
</body>